<?php

namespace app\admin\controller;


use app\user\logic\ShareLinkLogic;
use think\Controller;
use think\Db;
use \app\admin\model\Account as AccountModel;
use think\facade\Request;

class Account extends  Controller
{
    protected $middleware = [
        'app\http\middleware\checkAdminToken::class'
    ];

    //返回公众号列表
    public function index()
    {

        $data=AccountModel::order('id','asc')->all();
        $this->result($data, 200, '成功');
    }

    //添加
    public function create()
    {
        $app_id=Request::param('app_id',0);
        $app_secret=Request::param('app_secret',0);

        $account = new AccountModel();
        $account->app_id = $app_id;
        $account->app_secret = $app_secret;
        $account->add_time = time();
        $res = $account->save();
        if($res){
            $this->result($res,200,'新增成功');
        }
    }

    //修改
    public function update()
    {
        $account_id=Request::param('account_id');
        $app_id=Request::param('app_id',0);
        $app_secret=Request::param('app_secret',0);

        $res = AccountModel::where('id', $account_id)
            ->update([
                "app_id" => $app_id,
                "app_secret" => $app_secret
            ]);

        if ($res) {
            $this->result('', 200, '修改成功');
        } else {
            $this->result('', 400, '修改失败');
        }
    }
    //删除指定banner
    public function delete()
    {
        $account_id=Request::param('account_id');

        $res=AccountModel::where([
            'id'=>$account_id
        ])->delete();

        if ($res) {
            $this->result('', 200, '删除成功');
        } else {
            $this->result('', 400, '删除失败');
        }
    }

}
